#include "AD7606_Ops.h"
#include "Drv_AD7606.h"
#include "spi.h"

static void read(uint16_t buffer[8]);
static void convert(void);
static uint8_t busyCheck(void);

AD7606Ops_T	AD7606_Drv_Ops = 
{
	.read = read,
	.convert = convert,
	.busyCheck = busyCheck,
};

static void read(uint16_t buffer[8])
{
	HAL_GPIO_WritePin(SPI3_Cs_GPIO_Port, SPI3_Cs_Pin, GPIO_PIN_RESET);
	HAL_SPI_Receive(&hspi3,(uint8_t *)buffer,8,0x01);		
	HAL_GPIO_WritePin(SPI3_Cs_GPIO_Port, SPI3_Cs_Pin, GPIO_PIN_SET);
}

static void convert(void)
{
	AD7606CONVST_High(CONVSET_2_GPIO_Port,CONVSET_2_Pin);
	AD7606CONVST_LOW(CONVSET_2_GPIO_Port,CONVSET_2_Pin);
	HAL_Delay(1);
	AD7606CONVST_High(CONVSET_2_GPIO_Port,CONVSET_2_Pin);
}

static uint8_t busyCheck(void)
{
	return !HAL_GPIO_ReadPin(BUSY_2_GPIO_Port, BUSY_2_Pin);
}

